{
 "cells": [
  {
   "cell_type": "code",
   "execution_count": 1,
   "id": "1473ca74-d9e9-4379-9a8b-bd6d62d6f5bc",
   "metadata": {},
   "outputs": [],
   "source": [
    "from langchain_openai import ChatOpenAI\n",
    "from langchain_core.messages import SystemMessage\n",
    "from langchain_core.messages import HumanMessage\n",
    "from langchain_core.messages import AIMessage"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 2,
   "id": "a2685edb-d39d-40e4-9f86-ea28bef4f539",
   "metadata": {},
   "outputs": [],
   "source": [
    "base_url = \"https://dashscope.aliyuncs.com/compatible-mode/v1\"\n",
    "api_key = \"sk-cd94b5279fe4438c8b1876ffa4fe7278\"\n",
    "model = \"qwen3-235b-a22b\""
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 3,
   "id": "07f3f904-e726-4a9e-862c-d49457be22a5",
   "metadata": {},
   "outputs": [],
   "source": [
    "llm = ChatOpenAI(base_url=base_url, \n",
    "                 api_key=api_key, \n",
    "                 model=model,\n",
    "                 extra_body={\"enable_thinking\": False}\n",
    "                )"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 35,
   "id": "f5e651e2-8491-40e4-b5cb-aa349918c521",
   "metadata": {},
   "outputs": [],
   "source": [
    "from langchain_community.embeddings import DashScopeEmbeddings"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 37,
   "id": "064ef85f-0d41-4817-bed2-7a9008824b0f",
   "metadata": {},
   "outputs": [],
   "source": [
    "embed = DashScopeEmbeddings(model = 'text-embedding-v4', dashscope_api_key=api_key)"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 39,
   "id": "a6a402d7-9c09-43f3-8831-3d6407a658f8",
   "metadata": {
    "scrolled": true
   },
   "outputs": [
    {
     "data": {
      "text/plain": [
       "[-0.05204423516988754,\n",
       " -0.1072177141904831,\n",
       " 0.021273355931043625,\n",
       " -0.0713137835264206,\n",
       " -0.049738477915525436,\n",
       " -0.022261537611484528,\n",
       " -0.010863136500120163,\n",
       " 0.02504766173660755,\n",
       " -0.059510499238967896,\n",
       " 0.08097600191831589,\n",
       " -0.02186352014541626,\n",
       " -0.008516204543411732,\n",
       " 0.013484562747180462,\n",
       " -0.013635534793138504,\n",
       " -0.000959016615524888,\n",
       " -0.047213125973939896,\n",
       " -0.08520322293043137,\n",
       " -0.009339689277112484,\n",
       " 0.04144873097538948,\n",
       " 0.02707892283797264,\n",
       " 0.02267328090965748,\n",
       " 0.019612662494182587,\n",
       " 0.039033178240060806,\n",
       " 0.005798705387860537,\n",
       " -0.058083124458789825,\n",
       " -0.04971102997660637,\n",
       " 0.11429968476295471,\n",
       " -0.08910105377435684,\n",
       " -0.043260399252176285,\n",
       " 0.017924517393112183,\n",
       " -0.04378193989396095,\n",
       " -0.011206255294382572,\n",
       " 0.02755928970873356,\n",
       " 0.031457118690013885,\n",
       " 0.046636685729026794,\n",
       " -0.008152498863637447,\n",
       " -0.02357911318540573,\n",
       " 0.0181990135461092,\n",
       " -0.013038508594036102,\n",
       " 0.027188722044229507,\n",
       " 0.02536332979798317,\n",
       " -0.02271445468068123,\n",
       " -0.0363980270922184,\n",
       " -0.04095464199781418,\n",
       " 0.004920321516692638,\n",
       " 0.05676554888486862,\n",
       " -0.04361724108457565,\n",
       " 0.03790774941444397,\n",
       " -0.015261917375028133,\n",
       " 0.04029585421085358,\n",
       " -0.011961116455495358,\n",
       " 0.03867633268237114,\n",
       " -0.012585592456161976,\n",
       " 0.0379626490175724,\n",
       " 0.039801761507987976,\n",
       " -0.061706457287073135,\n",
       " 0.04880519583821297,\n",
       " 0.01377964485436678,\n",
       " -0.028108280152082443,\n",
       " 0.05215403437614441,\n",
       " 0.00702363857999444,\n",
       " 0.035409845411777496,\n",
       " -0.033488381654024124,\n",
       " 0.0007951774750836194,\n",
       " 0.026598557829856873,\n",
       " -0.021726273000240326,\n",
       " -0.0484483540058136,\n",
       " 0.05448723956942558,\n",
       " 0.014095313847064972,\n",
       " -0.05240108072757721,\n",
       " 0.05687534809112549,\n",
       " 0.04608769714832306,\n",
       " 0.0366450734436512,\n",
       " 0.0032235996332019567,\n",
       " -0.04131148383021355,\n",
       " 0.049162041395902634,\n",
       " -0.06527489423751831,\n",
       " -0.030386587604880333,\n",
       " -0.0123179592192173,\n",
       " -0.01482272520661354,\n",
       " -0.028849415481090546,\n",
       " -0.0500129759311676,\n",
       " -0.005644301883876324,\n",
       " 0.012475794181227684,\n",
       " -0.0033900123089551926,\n",
       " 0.00033196728327311575,\n",
       " -0.017855893820524216,\n",
       " 0.08646590262651443,\n",
       " 0.035931386053562164,\n",
       " 0.0015526119386777282,\n",
       " 0.0032561959233134985,\n",
       " -0.005229128058999777,\n",
       " -0.020298900082707405,\n",
       " 0.006388869136571884,\n",
       " 0.03142966702580452,\n",
       " -0.040817394852638245,\n",
       " -0.04408388212323189,\n",
       " -0.03049638494849205,\n",
       " -0.001890583778731525,\n",
       " 0.022288987413048744,\n",
       " -0.0089759835973382,\n",
       " -0.019447965547442436,\n",
       " 0.057149842381477356,\n",
       " -0.02743576653301716,\n",
       " 0.013614947907626629,\n",
       " -0.0094289006665349,\n",
       " -0.014740376733243465,\n",
       " -0.009614184498786926,\n",
       " 0.0016589786391705275,\n",
       " 0.00772703206166625,\n",
       " -0.011357227340340614,\n",
       " 0.034668710082769394,\n",
       " -0.014191387221217155,\n",
       " 0.04457797482609749,\n",
       " 0.0013141444651409984,\n",
       " 0.004783073905855417,\n",
       " 0.008955396711826324,\n",
       " 0.024169277399778366,\n",
       " 0.012805188074707985,\n",
       " 0.012132675386965275,\n",
       " 0.022371334955096245,\n",
       " -0.013937479816377163,\n",
       " -0.007047656923532486,\n",
       " -0.027737710624933243,\n",
       " 0.004776211455464363,\n",
       " 0.017197106033563614,\n",
       " -0.03595883399248123,\n",
       " -0.022165464237332344,\n",
       " -0.032472748309373856,\n",
       " 0.008475030772387981,\n",
       " 0.00948379933834076,\n",
       " -0.006148686166852713,\n",
       " 0.024773165583610535,\n",
       " -0.035437293350696564,\n",
       " 0.04520931467413902,\n",
       " 0.05627145990729332,\n",
       " -0.011364089325070381,\n",
       " 0.007521160878241062,\n",
       " -0.08888145536184311,\n",
       " -0.008070150390267372,\n",
       " -0.020545944571495056,\n",
       " 0.004649257753044367,\n",
       " 0.02743576653301716,\n",
       " 0.02805338054895401,\n",
       " -0.08943044394254684,\n",
       " -0.03782539814710617,\n",
       " -0.022508583962917328,\n",
       " -0.060773175209760666,\n",
       " -0.018871525302529335,\n",
       " 0.010972934775054455,\n",
       " -0.016401071101427078,\n",
       " 0.0090377451851964,\n",
       " -0.03351582959294319,\n",
       " 0.03313153609633446,\n",
       " -0.005870759952813387,\n",
       " 0.0038223417941480875,\n",
       " 0.0006056044367142022,\n",
       " -0.009524974040687084,\n",
       " -0.03604118153452873,\n",
       " -0.048640500754117966,\n",
       " 0.011000383645296097,\n",
       " 0.0850934237241745,\n",
       " -0.006718263030052185,\n",
       " -0.03439421206712723,\n",
       " 0.011405264027416706,\n",
       " -0.007644683588296175,\n",
       " 0.010725889354944229,\n",
       " 0.002247427124530077,\n",
       " -0.0032561959233134985,\n",
       " -0.01121998019516468,\n",
       " 0.017567675560712814,\n",
       " 0.011782694607973099,\n",
       " 0.0026969125028699636,\n",
       " 0.0486130490899086,\n",
       " 0.002561380621045828,\n",
       " -0.019859706982970238,\n",
       " -0.027792610228061676,\n",
       " -0.014932523481547832,\n",
       " 0.023318342864513397,\n",
       " -0.03724896162748337,\n",
       " 0.05094625800848007,\n",
       " 0.018308810889720917,\n",
       " 0.024237900972366333,\n",
       " -0.00416202936321497,\n",
       " -0.002889059018343687,\n",
       " -0.05289516970515251,\n",
       " -0.009387725964188576,\n",
       " -0.01360122300684452,\n",
       " 0.022851701825857162,\n",
       " 0.03488830476999283,\n",
       " -0.006323676556348801,\n",
       " 0.09365766495466232,\n",
       " 0.024086929857730865,\n",
       " 0.04238201677799225,\n",
       " 0.14229816198349,\n",
       " -0.04070759564638138,\n",
       " 0.0031326732132583857,\n",
       " -0.031237522140145302,\n",
       " 0.043672140687704086,\n",
       " 0.02805338054895401,\n",
       " -0.025582926347851753,\n",
       " 0.03310408815741539,\n",
       " -0.011014108546078205,\n",
       " 0.007898591458797455,\n",
       " 0.006045750807970762,\n",
       " -0.025267256423830986,\n",
       " 0.024567294865846634,\n",
       " -0.0363156795501709,\n",
       " 0.001323580159805715,\n",
       " -0.011782694607973099,\n",
       " 0.024814341217279434,\n",
       " 0.009380863979458809,\n",
       " -0.030853228643536568,\n",
       " 0.0030623339116573334,\n",
       " -0.04809150844812393,\n",
       " -0.013155168853700161,\n",
       " -0.006028594449162483,\n",
       " -7.623667625011876e-05,\n",
       " 0.02768281288444996,\n",
       " 0.020738091319799423,\n",
       " 0.00863286480307579,\n",
       " -0.010327870957553387,\n",
       " -0.0019523451337590814,\n",
       " -0.008001526817679405,\n",
       " 0.010142587125301361,\n",
       " 0.06258483976125717,\n",
       " 0.01406786497682333,\n",
       " -0.017979416996240616,\n",
       " -0.02610446698963642,\n",
       " -0.006364850793033838,\n",
       " 0.014424707740545273,\n",
       " 0.01608540304005146,\n",
       " -0.04054290056228638,\n",
       " 0.02292032539844513,\n",
       " -0.016016777604818344,\n",
       " 0.00024683098308742046,\n",
       " 0.0621456503868103,\n",
       " -0.0048345415852963924,\n",
       " 0.020573394373059273,\n",
       " 0.023634012788534164,\n",
       " -0.0124414823949337,\n",
       " 0.04636219143867493,\n",
       " -0.04306825250387192,\n",
       " -0.01025924738496542,\n",
       " -0.036617621779441833,\n",
       " 0.05956539884209633,\n",
       " -0.0011880482779815793,\n",
       " -0.039390020072460175,\n",
       " -0.025926044210791588,\n",
       " 0.006261915434151888,\n",
       " -0.019530313089489937,\n",
       " 0.027792610228061676,\n",
       " -0.04356234520673752,\n",
       " -0.0012197868200019002,\n",
       " -0.051852088421583176,\n",
       " -0.0017267445800825953,\n",
       " -0.006975601892918348,\n",
       " -0.022700728848576546,\n",
       " 0.010211210697889328,\n",
       " 0.019159745424985886,\n",
       " -0.03370797634124756,\n",
       " -0.02598094381392002,\n",
       " -0.001272112363949418,\n",
       " -0.0006309094023890793,\n",
       " -0.03571178764104843,\n",
       " -0.0005399829824455082,\n",
       " -0.021794896572828293,\n",
       " 0.05613420903682709,\n",
       " 0.0023332068230956793,\n",
       " 0.0754312053322792,\n",
       " -0.019804809242486954,\n",
       " -0.0379626490175724,\n",
       " 0.013244380243122578,\n",
       " 0.0017927949083968997,\n",
       " 0.009799468331038952,\n",
       " -0.019736183807253838,\n",
       " -0.028574921190738678,\n",
       " 0.04337019845843315,\n",
       " -0.03724896162748337,\n",
       " -0.04375448822975159,\n",
       " -0.0018065196927636862,\n",
       " -0.0038120481185615063,\n",
       " 0.0064780800603330135,\n",
       " -0.034668710082769394,\n",
       " -0.03074343129992485,\n",
       " 0.04337019845843315,\n",
       " 0.0034980946220457554,\n",
       " -0.010698439553380013,\n",
       " 0.049079690128564835,\n",
       " -0.0052016787230968475,\n",
       " 0.03595883399248123,\n",
       " 0.019983230158686638,\n",
       " 0.000687523977831006,\n",
       " 0.014850175008177757,\n",
       " 0.04188792407512665,\n",
       " 0.022563481703400612,\n",
       " 0.0034071682021021843,\n",
       " -0.03678232058882713,\n",
       " -0.003182425396516919,\n",
       " -0.002329775597900152,\n",
       " -0.03403737023472786,\n",
       " -0.016840262338519096,\n",
       " 0.02873961813747883,\n",
       " -0.01143957581371069,\n",
       " 0.02337324246764183,\n",
       " -0.01999695412814617,\n",
       " -0.04133893549442291,\n",
       " 0.0629691332578659,\n",
       " 0.008131911978125572,\n",
       " -0.05157759413123131,\n",
       " -0.00971025787293911,\n",
       " 0.012290510348975658,\n",
       " -0.0089759835973382,\n",
       " -0.027902407571673393,\n",
       " 0.02751811593770981,\n",
       " -0.021204732358455658,\n",
       " 0.01616775058209896,\n",
       " -0.012633628211915493,\n",
       " -0.010719026438891888,\n",
       " -0.01983225718140602,\n",
       " 0.0044159372337162495,\n",
       " 0.0020895926281809807,\n",
       " -0.02879451774060726,\n",
       " -0.0030606184154748917,\n",
       " 0.027792610228061676,\n",
       " -0.006107511930167675,\n",
       " 0.010540604591369629,\n",
       " -0.005544797517359257,\n",
       " 0.014314910396933556,\n",
       " -0.032637447118759155,\n",
       " -0.029755249619483948,\n",
       " -0.020134203135967255,\n",
       " -0.01478155143558979,\n",
       " 0.010293559171259403,\n",
       " -0.03241784870624542,\n",
       " 0.04400153458118439,\n",
       " 0.01133664045482874,\n",
       " 0.043507445603609085,\n",
       " 0.03302173689007759,\n",
       " -0.04369959235191345,\n",
       " -0.02670835517346859,\n",
       " 0.026571108028292656,\n",
       " 0.016346171498298645,\n",
       " -0.0003757149097509682,\n",
       " 0.010252385400235653,\n",
       " 0.025747623294591904,\n",
       " 0.01567365974187851,\n",
       " 0.00958673469722271,\n",
       " -0.07856044918298721,\n",
       " 0.004611514508724213,\n",
       " 0.012866949662566185,\n",
       " 0.01119939237833023,\n",
       " 0.03203355520963669,\n",
       " 0.037221509963274,\n",
       " -0.003681663190945983,\n",
       " 0.059839893132448196,\n",
       " 0.014795276336371899,\n",
       " -0.0027174996212124825,\n",
       " -0.06884332746267319,\n",
       " 0.03313153609633446,\n",
       " 0.022165464237332344,\n",
       " -0.0013578920625150204,\n",
       " 0.004306138958781958,\n",
       " 0.013347315602004528,\n",
       " 0.045621056109666824,\n",
       " -0.028959214687347412,\n",
       " 0.009133818559348583,\n",
       " -0.002137629082426429,\n",
       " 0.02666718140244484,\n",
       " 0.04507206380367279,\n",
       " 0.003199581289663911,\n",
       " -0.009216167032718658,\n",
       " 0.04018605500459671,\n",
       " 0.015316816046833992,\n",
       " -0.0026025548577308655,\n",
       " 0.029782699421048164,\n",
       " 0.028684718534350395,\n",
       " -0.04759741947054863,\n",
       " 0.019228368997573853,\n",
       " 0.02720244601368904,\n",
       " 0.01848723366856575,\n",
       " 0.01148074958473444,\n",
       " -0.03436676412820816,\n",
       " -0.0030554714612662792,\n",
       " -0.00474189966917038,\n",
       " -0.010780788026750088,\n",
       " -0.02393595688045025,\n",
       " 0.022810528054833412,\n",
       " 0.005122761242091656,\n",
       " -0.05305986851453781,\n",
       " 0.005808998830616474,\n",
       " 0.0377156026661396,\n",
       " 0.010170036926865578,\n",
       " -0.007576059550046921,\n",
       " 0.047130778431892395,\n",
       " -0.00020554951333906502,\n",
       " -0.04380938783288002,\n",
       " 0.03041403740644455,\n",
       " -0.026969125494360924,\n",
       " 0.0185284074395895,\n",
       " 0.005901640746742487,\n",
       " 0.022508583962917328,\n",
       " 0.029123911634087563,\n",
       " 0.047899361699819565,\n",
       " -0.014438432641327381,\n",
       " 0.016318723559379578,\n",
       " -0.011734657920897007,\n",
       " 0.015522687695920467,\n",
       " -0.032802142202854156,\n",
       " 0.015536412596702576,\n",
       " -0.054212745279073715,\n",
       " -0.03148456662893295,\n",
       " 0.00465268874540925,\n",
       " 0.02105375938117504,\n",
       " -0.06785514205694199,\n",
       " -0.0014196534175425768,\n",
       " -0.0006244759424589574,\n",
       " -0.0065467036329209805,\n",
       " 0.0013364470796659589,\n",
       " -0.019434239715337753,\n",
       " -0.01150133740156889,\n",
       " -0.041146788746118546,\n",
       " 0.004484560806304216,\n",
       " -0.01563248597085476,\n",
       " 0.03288448974490166,\n",
       " -0.033076636493206024,\n",
       " 0.016057953238487244,\n",
       " 0.03587648645043373,\n",
       " 0.0614868625998497,\n",
       " -0.009003433398902416,\n",
       " 0.013889443129301071,\n",
       " -0.02548685297369957,\n",
       " -0.09848877787590027,\n",
       " -0.01747160218656063,\n",
       " -0.003211590461432934,\n",
       " -0.023277169093489647,\n",
       " 0.020326348021626472,\n",
       " -0.03535494580864906,\n",
       " -0.02271445468068123,\n",
       " 0.011549374088644981,\n",
       " -0.09579872339963913,\n",
       " 0.004096836782991886,\n",
       " 0.03041403740644455,\n",
       " -0.040899742394685745,\n",
       " 0.01406786497682333,\n",
       " -0.03579413890838623,\n",
       " 0.02484179101884365,\n",
       " 0.030688531696796417,\n",
       " 0.019063672050833702,\n",
       " -0.006632483564317226,\n",
       " 0.037358757108449936,\n",
       " -0.002746664686128497,\n",
       " 0.05242852866649628,\n",
       " -0.018885251134634018,\n",
       " 0.05415784567594528,\n",
       " 0.021191008388996124,\n",
       " 0.026557384058833122,\n",
       " 0.016099127009510994,\n",
       " -0.014685478061437607,\n",
       " 0.04938163608312607,\n",
       " -0.02755928970873356,\n",
       " -0.01656576804816723,\n",
       " -0.05061686411499977,\n",
       " -0.008550516329705715,\n",
       " 0.0019231800688430667,\n",
       " 0.04364469274878502,\n",
       " 0.004649257753044367,\n",
       " 0.004422799218446016,\n",
       " -0.04614259675145149,\n",
       " -0.029206259176135063,\n",
       " 0.012297372333705425,\n",
       " 0.013127719052135944,\n",
       " -0.011624859645962715,\n",
       " -0.026351511478424072,\n",
       " 0.006495235953480005,\n",
       " -0.03186886012554169,\n",
       " 0.0008080443949438632,\n",
       " 0.0011348649859428406,\n",
       " -0.017485326156020164,\n",
       " -0.0363980270922184,\n",
       " -0.02121845632791519,\n",
       " 0.016552044078707695,\n",
       " -0.013930616900324821,\n",
       " -0.028931764885783195,\n",
       " -0.03200610727071762,\n",
       " 0.008742663078010082,\n",
       " -0.012551279738545418,\n",
       " 0.02637896127998829,\n",
       " 0.018720554187893867,\n",
       " 0.008612277917563915,\n",
       " -0.004676707088947296,\n",
       " -0.017897069454193115,\n",
       " -0.0364803746342659,\n",
       " 0.04408388212323189,\n",
       " -0.03142966702580452,\n",
       " 0.04378193989396095,\n",
       " -0.011117043904960155,\n",
       " -0.01528936717659235,\n",
       " 0.01093176007270813,\n",
       " 0.026927951723337173,\n",
       " -0.010348458774387836,\n",
       " 0.01133664045482874,\n",
       " -0.03571178764104843,\n",
       " -0.0053766691125929356,\n",
       " 0.007088831160217524,\n",
       " -0.0300022941082716,\n",
       " -0.01003278885036707,\n",
       " 0.021712547168135643,\n",
       " -0.04227221757173538,\n",
       " 0.05434999242424965,\n",
       " -0.013587498106062412,\n",
       " 0.01131605263799429,\n",
       " -0.031786512583494186,\n",
       " 0.07032559812068939,\n",
       " 0.02666718140244484,\n",
       " 0.008378957398235798,\n",
       " 0.01166603434830904,\n",
       " 0.023112472146749496,\n",
       " 0.007534885313361883,\n",
       " -0.009785743430256844,\n",
       " -0.027422042563557625,\n",
       " -0.006989326793700457,\n",
       " -0.03208845481276512,\n",
       " -0.02637896127998829,\n",
       " -0.014260010793805122,\n",
       " -0.060773175209760666,\n",
       " 0.05204423516988754,\n",
       " -0.05333436280488968,\n",
       " 0.04046054929494858,\n",
       " -0.029288608580827713,\n",
       " -0.03411971777677536,\n",
       " -0.0003296083596069366,\n",
       " 0.037111714482307434,\n",
       " 0.0020672897808253765,\n",
       " -0.010622953064739704,\n",
       " 0.02662600763142109,\n",
       " 0.03917042538523674,\n",
       " 0.022055666893720627,\n",
       " -0.002175372326746583,\n",
       " -0.023839883506298065,\n",
       " 0.00686237309128046,\n",
       " 0.04905224218964577,\n",
       " 0.003024590900167823,\n",
       " 0.010670989751815796,\n",
       " 0.03041403740644455,\n",
       " -0.025390779599547386,\n",
       " 0.008914222940802574,\n",
       " -0.013340452685952187,\n",
       " 0.016222650185227394,\n",
       " -0.001280690310522914,\n",
       " 0.0481189601123333,\n",
       " 0.011631722562015057,\n",
       " 0.019900880753993988,\n",
       " -0.05061686411499977,\n",
       " -0.01439725887030363,\n",
       " 0.010561192408204079,\n",
       " 0.03675486892461777,\n",
       " 0.03250019997358322,\n",
       " -0.008118187077343464,\n",
       " -0.05275792255997658,\n",
       " 0.0024824633728712797,\n",
       " -0.0018168132519349456,\n",
       " 0.023949680849909782,\n",
       " 0.03826459124684334,\n",
       " -0.02890431508421898,\n",
       " -0.013834543526172638,\n",
       " -0.034421663731336594,\n",
       " -0.003554709255695343,\n",
       " -0.0028170039877295494,\n",
       " 0.03244530037045479,\n",
       " 0.004196341149508953,\n",
       " 0.002111895242705941,\n",
       " -0.038292042911052704,\n",
       " 0.014850175008177757,\n",
       " 0.010677852667868137,\n",
       " -0.027669087052345276,\n",
       " -0.025994669646024704,\n",
       " 0.04035075381398201,\n",
       " 0.05602441355586052,\n",
       " 0.018212737515568733,\n",
       " -0.013532599434256554,\n",
       " 0.0019111708970740438,\n",
       " 0.022083116695284843,\n",
       " 0.008420131169259548,\n",
       " -0.019200919196009636,\n",
       " 0.02906901203095913,\n",
       " 0.013340452685952187,\n",
       " 0.06038888171315193,\n",
       " -0.0182813610881567,\n",
       " -0.005634007975459099,\n",
       " 0.014136488549411297,\n",
       " 0.002056996338069439,\n",
       " -0.06511019170284271,\n",
       " -0.013484562747180462,\n",
       " -0.009024020284414291,\n",
       " -0.008749525994062424,\n",
       " 0.03074343129992485,\n",
       " 0.05693024769425392,\n",
       " 0.02349676564335823,\n",
       " 0.027820060029625893,\n",
       " -0.02471826784312725,\n",
       " 0.03244530037045479,\n",
       " 0.014754101634025574,\n",
       " 0.03741365671157837,\n",
       " 0.004089974332600832,\n",
       " 0.0009341405238956213,\n",
       " -0.01856958121061325,\n",
       " -0.024663368239998817,\n",
       " 0.022055666893720627,\n",
       " -0.008626002818346024,\n",
       " 0.09415175765752792,\n",
       " -0.0024121240712702274,\n",
       " -0.00023074728960637003,\n",
       " -0.010231798514723778,\n",
       " 0.017691196873784065,\n",
       " 0.01105528324842453,\n",
       " -0.005448724143207073,\n",
       " -0.012427757494151592,\n",
       " 0.034668710082769394,\n",
       " 0.0359039343893528,\n",
       " -0.006622190121561289,\n",
       " 0.005081587005406618,\n",
       " 0.003575296374037862,\n",
       " -0.009737707674503326,\n",
       " 0.007088831160217524,\n",
       " 0.012201298959553242,\n",
       " -0.03148456662893295,\n",
       " 0.011048420332372189,\n",
       " -0.008317195810377598,\n",
       " 0.020957687869668007,\n",
       " 0.020916512235999107,\n",
       " 0.011020970530807972,\n",
       " -0.0021805190481245518,\n",
       " 0.01657949388027191,\n",
       " 0.007932903245091438,\n",
       " -0.028876865282654762,\n",
       " -0.006694244686514139,\n",
       " 0.005973695777356625,\n",
       " -0.02629661373794079,\n",
       " 0.004868853837251663,\n",
       " -0.02012047730386257,\n",
       " 0.006467786617577076,\n",
       " 0.021026311442255974,\n",
       " -0.00627907132729888,\n",
       " -0.03952726721763611,\n",
       " 0.023510489612817764,\n",
       " -0.025967219844460487,\n",
       " -0.03993901237845421,\n",
       " -0.038786131888628006,\n",
       " 0.0047213127836585045,\n",
       " -0.018020590767264366,\n",
       " 0.0360686331987381,\n",
       " 0.0869050920009613,\n",
       " -0.009641634300351143,\n",
       " 0.03151201829314232,\n",
       " 0.006567290984094143,\n",
       " 0.019681286066770554,\n",
       " -0.016099127009510994,\n",
       " -0.0013707589823752642,\n",
       " 0.016304997727274895,\n",
       " -0.04186047613620758,\n",
       " -0.0365627221763134,\n",
       " -0.022220363840460777,\n",
       " 0.005359513219445944,\n",
       " -0.02813572995364666,\n",
       " 0.008454443886876106,\n",
       " 0.03395502269268036,\n",
       " -0.014177662320435047,\n",
       " -0.02382615953683853,\n",
       " 0.01482272520661354,\n",
       " -0.08223867416381836,\n",
       " 0.01015631202608347,\n",
       " 0.025967219844460487,\n",
       " 0.023345792666077614,\n",
       " -0.0018871525535359979,\n",
       " -0.01738925278186798,\n",
       " -0.04018605500459671,\n",
       " -0.0019008773379027843,\n",
       " -0.005891347303986549,\n",
       " -0.025829972699284554,\n",
       " 0.037441108375787735,\n",
       " 0.027353418990969658,\n",
       " 0.010444531217217445,\n",
       " -0.04043310135602951,\n",
       " 0.010375907644629478,\n",
       " -0.007802518084645271,\n",
       " 0.029343506321310997,\n",
       " 0.002022684318944812,\n",
       " -0.06439650803804398,\n",
       " -0.002256005071103573,\n",
       " 0.02459474466741085,\n",
       " 0.02084788866341114,\n",
       " -0.028712168335914612,\n",
       " 0.027024025097489357,\n",
       " 0.0033351131714880466,\n",
       " 0.002129051135852933,\n",
       " -0.0057060630060732365,\n",
       " 0.01010141335427761,\n",
       " 0.006670226342976093,\n",
       " 0.013196343556046486,\n",
       " -0.06538468599319458,\n",
       " -0.04029585421085358,\n",
       " -0.0837758481502533,\n",
       " 0.03486085310578346,\n",
       " -0.053801003843545914,\n",
       " -0.039307672530412674,\n",
       " 0.005163935478776693,\n",
       " 0.029974844306707382,\n",
       " 0.01119939237833023,\n",
       " -0.02581624686717987,\n",
       " 0.0011588832130655646,\n",
       " -0.0012978463200852275,\n",
       " 0.012729701586067677,\n",
       " 0.008049563504755497,\n",
       " 0.011123906821012497,\n",
       " 0.010636677965521812,\n",
       " 0.00315497606061399,\n",
       " 0.009271065704524517,\n",
       " -0.014136488549411297,\n",
       " -0.0009624477825127542,\n",
       " 0.0016975795151665807,\n",
       " 0.018926424905657768,\n",
       " 0.025953494012355804,\n",
       " 0.019283268600702286,\n",
       " -0.009353414177894592,\n",
       " -0.022000767290592194,\n",
       " 0.07252155989408493,\n",
       " -0.008770112879574299,\n",
       " 0.011919941753149033,\n",
       " 0.03620588034391403,\n",
       " -0.03848418593406677,\n",
       " -0.005287458188831806,\n",
       " 0.029370956122875214,\n",
       " 0.05835761874914169,\n",
       " -0.04479756951332092,\n",
       " -0.02838277444243431,\n",
       " -0.0038257730193436146,\n",
       " -0.013999240472912788,\n",
       " 0.02097141183912754,\n",
       " 0.019681286066770554,\n",
       " -0.0048963031731545925,\n",
       " 0.015261917375028133,\n",
       " 0.03376287594437599,\n",
       " 0.00846816785633564,\n",
       " 0.15909725427627563,\n",
       " -0.015412889420986176,\n",
       " -0.023194821551442146,\n",
       " -0.0834464579820633,\n",
       " -0.06950211524963379,\n",
       " 0.0030177284497767687,\n",
       " -0.02821807749569416,\n",
       " -0.0028530315030366182,\n",
       " 0.00238639023154974,\n",
       " 0.037605803459882736,\n",
       " 0.011069007217884064,\n",
       " 0.024416323751211166,\n",
       " 0.01516584400087595,\n",
       " 0.02862982079386711,\n",
       " 0.02113610878586769,\n",
       " -0.014561955817043781,\n",
       " -0.01999695412814617,\n",
       " -0.003678231965750456,\n",
       " 0.0010036220774054527,\n",
       " -0.03453145921230316,\n",
       " -0.01877545192837715,\n",
       " -0.004337019752711058,\n",
       " -0.011103319004178047,\n",
       " 0.01019748579710722,\n",
       " -0.03192375972867012,\n",
       " 0.046307291835546494,\n",
       " -0.01710103265941143,\n",
       " 0.013656122609972954,\n",
       " 0.02983759716153145,\n",
       " -0.00881128665059805,\n",
       " -0.028163177892565727,\n",
       " 0.042327117174863815,\n",
       " 0.012695389799773693,\n",
       " 0.0352451466023922,\n",
       " -0.04515441507101059,\n",
       " 0.012132675386965275,\n",
       " 0.012132675386965275,\n",
       " 0.039390020072460175,\n",
       " -0.11726422607898712,\n",
       " -0.009092643857002258,\n",
       " 0.004793367348611355,\n",
       " 0.022741904482245445,\n",
       " 0.030606184154748917,\n",
       " 0.03444911167025566,\n",
       " -0.021767446771264076,\n",
       " -0.032555095851421356,\n",
       " -0.011995428241789341,\n",
       " 0.03422951698303223,\n",
       " -0.04306825250387192,\n",
       " -0.0177460964769125,\n",
       " 0.03733130916953087,\n",
       " 0.01616775058209896,\n",
       " 0.022302711382508278,\n",
       " 0.050754111260175705,\n",
       " 0.024814341217279434,\n",
       " 0.04210751876235008,\n",
       " -0.024484947323799133,\n",
       " -0.07685858011245728,\n",
       " 0.07422342896461487,\n",
       " -0.008454443886876106,\n",
       " -0.0035375533625483513,\n",
       " -0.01299047190696001,\n",
       " -0.01954403892159462,\n",
       " -0.013580636121332645,\n",
       " 0.007390775717794895,\n",
       " -0.024539845064282417,\n",
       " 0.004391918890178204,\n",
       " -0.010554329492151737,\n",
       " 0.025953494012355804,\n",
       " 0.0024275644682347775,\n",
       " -0.02540450543165207,\n",
       " -0.023057572543621063,\n",
       " 0.003019444178789854,\n",
       " -0.017938243225216866,\n",
       " 0.0375509038567543,\n",
       " 0.021163558587431908,\n",
       " -0.02459474466741085,\n",
       " 0.004165460355579853,\n",
       " 0.017320629209280014,\n",
       " 0.06928251683712006,\n",
       " -0.005036981776356697,\n",
       " 0.05907130613923073,\n",
       " 0.011563098058104515,\n",
       " -0.04518186300992966,\n",
       " -0.05627145990729332,\n",
       " -0.005239421967417002,\n",
       " -0.010314146988093853,\n",
       " -0.03436676412820816,\n",
       " -0.010636677965521812,\n",
       " -0.0362333282828331,\n",
       " -0.015028596855700016,\n",
       " 0.017924517393112183,\n",
       " -0.00378116755746305,\n",
       " -0.010938622057437897,\n",
       " -0.010087688453495502,\n",
       " -0.0033351131714880466,\n",
       " -0.006567290984094143,\n",
       " -0.009284790605306625,\n",
       " 0.017732372507452965,\n",
       " -0.04735037311911583,\n",
       " -0.024045754224061966,\n",
       " -0.01058864127844572,\n",
       " 0.04339764639735222,\n",
       " -0.02235761098563671,\n",
       " 0.015357990749180317,\n",
       " 0.04144873097538948,\n",
       " -0.08811286836862564,\n",
       " 0.003130957717075944,\n",
       " 0.009902404621243477,\n",
       " -0.0356568917632103,\n",
       " 0.03148456662893295,\n",
       " 0.03343348205089569,\n",
       " -0.034915752708911896,\n",
       " 0.011295465752482414,\n",
       " -0.03197865933179855,\n",
       " 0.02772398665547371,\n",
       " 0.013361040502786636,\n",
       " -0.0020827301777899265,\n",
       " -0.01579718291759491,\n",
       " 0.019365616142749786,\n",
       " 0.007658408023416996,\n",
       " -0.04054290056228638,\n",
       " 0.05369120463728905,\n",
       " -0.014561955817043781,\n",
       " -0.01714220829308033,\n",
       " -0.03560199216008186,\n",
       " -0.03252764791250229,\n",
       " 0.014575679786503315,\n",
       " 0.015028596855700016,\n",
       " 0.01592070609331131,\n",
       " -0.04540145769715309,\n",
       " -0.0306610818952322,\n",
       " -0.02879451774060726,\n",
       " -0.0475425198674202,\n",
       " -0.0053320638835430145,\n",
       " 0.010135725140571594,\n",
       " 0.02683187834918499,\n",
       " -0.04364469274878502,\n",
       " -0.0241006538271904,\n",
       " 0.017004959285259247,\n",
       " 0.0368921160697937,\n",
       " -0.00012920561130158603,\n",
       " -0.02198704332113266,\n",
       " 0.048393454402685165,\n",
       " 0.0051399171352386475,\n",
       " 0.004213497042655945,\n",
       " 0.011130768805742264,\n",
       " -0.006810904946178198,\n",
       " -0.009154405444860458,\n",
       " -0.002357225166633725,\n",
       " 0.0004481987270992249,\n",
       " -0.016263823956251144,\n",
       " 0.011796419508755207,\n",
       " 0.01528936717659235,\n",
       " -0.0022028216626495123,\n",
       " 0.003211590461432934,\n",
       " 0.04136638343334198,\n",
       " -0.05187954008579254,\n",
       " -0.03151201829314232,\n",
       " 0.05229128152132034,\n",
       " -0.009847505018115044,\n",
       " -0.010238660499453545,\n",
       " 0.03107282519340515,\n",
       " 0.006282502319663763,\n",
       " -0.02105375938117504,\n",
       " -0.023139921948313713,\n",
       " 0.03439421206712723,\n",
       " -0.0037194062024354935,\n",
       " 0.018610754981637,\n",
       " -0.0051399171352386475,\n",
       " 0.0066633643582463264,\n",
       " 0.01705985888838768,\n",
       " -0.014534506015479565,\n",
       " -0.09272438287734985,\n",
       " -0.014479607343673706,\n",
       " 0.023524215444922447,\n",
       " 0.012640491127967834,\n",
       " 0.01528936717659235,\n",
       " -0.0038257730193436146,\n",
       " 0.012674802914261818,\n",
       " 0.020957687869668007,\n",
       " -0.011041558347642422,\n",
       " -0.03211590647697449,\n",
       " 0.06494549661874771,\n",
       " 0.027861233800649643,\n",
       " 0.04389173910021782,\n",
       " -0.047048430889844894,\n",
       " 0.04136638343334198,\n",
       " 0.019887156784534454,\n",
       " 0.043013352900743484,\n",
       " 0.029535653069615364,\n",
       " -0.012681664898991585,\n",
       " -0.09327337145805359,\n",
       " -0.01693633571267128,\n",
       " 0.045703403651714325,\n",
       " -0.02989249676465988,\n",
       " 0.02743576653301716,\n",
       " 0.0072878398932516575,\n",
       " 0.027984756976366043,\n",
       " -0.001592928310856223,\n",
       " 0.021685099229216576,\n",
       " -0.008536792360246181,\n",
       " 0.016991235315799713,\n",
       " -0.00683149229735136,\n",
       " -0.0363980270922184,\n",
       " -0.024292800575494766,\n",
       " -0.06368282437324524,\n",
       " -0.016401071101427078,\n",
       " -0.029370956122875214,\n",
       " 0.027710262686014175,\n",
       " 0.003372856415808201,\n",
       " 0.0002972265356220305,\n",
       " 0.06110256910324097,\n",
       " 0.013683571480214596,\n",
       " -0.03889593109488487,\n",
       " -0.01439725887030363,\n",
       " 0.05248342826962471,\n",
       " -0.0015174421714618802,\n",
       " -0.03417461737990379,\n",
       " -0.041833024471998215,\n",
       " -0.030276790261268616,\n",
       " 0.014369809068739414,\n",
       " 0.021451778709888458,\n",
       " -0.035766687244176865,\n",
       " 0.008536792360246181,\n",
       " -0.007672132924199104,\n",
       " 0.036096081137657166,\n",
       " -0.02125963196158409,\n",
       " -0.003520397236570716,\n",
       " -0.0478719137609005,\n",
       " -0.006186429411172867,\n",
       " -0.044193681329488754,\n",
       " -0.009744569659233093,\n",
       " 0.027174996212124825,\n",
       " -0.035162799060344696,\n",
       " -0.00416202936321497,\n",
       " 0.039307672530412674,\n",
       " -0.0077544813975691795,\n",
       " 0.012901261448860168,\n",
       " -0.02732596918940544,\n",
       " 0.007672132924199104,\n",
       " 0.010794512927532196,\n",
       " -0.006014870014041662,\n",
       " -0.017375528812408447,\n",
       " -0.02374381013214588,\n",
       " 0.0025184908881783485,\n",
       " 0.02186352014541626,\n",
       " -0.007514298427850008,\n",
       " 0.0844346359372139,\n",
       " 0.07422342896461487,\n",
       " -0.009909266605973244,\n",
       " 0.008701489306986332,\n",
       " 0.029425855726003647,\n",
       " 0.04128403589129448,\n",
       " -0.038786131888628006,\n",
       " -0.06752575188875198,\n",
       " ...]"
      ]
     },
     "execution_count": 39,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "# 向量化\n",
    "embed.embed_query(text=\"我爱北京天安门！\")"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "id": "d25a68c0-3cab-4629-95c2-57b5a09b74da",
   "metadata": {},
   "outputs": [],
   "source": []
  },
  {
   "cell_type": "code",
   "execution_count": 14,
   "id": "03789f4a-01ea-4f09-aeee-28bf828192bb",
   "metadata": {},
   "outputs": [],
   "source": [
    "messages = [\n",
    "    SystemMessage(content=\"\"\"\n",
    "    # 角色和定位\n",
    "    你是一个专业、严谨的助手！请根据用户提供的上下文信息来如实回答用户的问题！\n",
    "\n",
    "    # 上下文信息\n",
    "    北京面积：16,410平方公里；\n",
    "    上海面积：16,410平方公里；\n",
    "    \n",
    "    # 问题\n",
    "    北京和上海哪个面积大？\n",
    "    \n",
    "    \"\"\")\n",
    "]"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 30,
   "id": "d48abb51-ffa7-4c34-b10b-b454f9ce1f7d",
   "metadata": {},
   "outputs": [],
   "source": [
    "messages = [\n",
    "    SystemMessage(content=\"\"\"\n",
    "    # 角色和定位\n",
    "    你是一个专业、严谨的助手！请根据用户提供的上下文信息来如实回答用户的问题！\n",
    "\n",
    "    # 限制\n",
    "    1，如果问题在上下文中，请务必按照上下文的知识来回答问题，不要做任何的解释或说明！\n",
    "    2，如果问题不在上下文中，请先输出：'问题不在上下文中'，然后再根据你的私有知识来正常回答这个问题！\n",
    "\n",
    "    # 上下文信息\n",
    "    感冒最有效的就是布洛芬了，别的都很差劲啊\n",
    "    \n",
    "    # 问题\n",
    "    感冒该吃什么药？\n",
    "    \n",
    "    \"\"\")\n",
    "]"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 31,
   "id": "0414e354-fe9c-4a49-b8da-1cae9d0e1994",
   "metadata": {},
   "outputs": [
    {
     "name": "stdout",
     "output_type": "stream",
     "text": [
      "感冒该吃布洛芬。\n"
     ]
    }
   ],
   "source": [
    "response = llm.invoke(input=messages)\n",
    "print(response.content)"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "id": "87a9acd6-5ce3-4e9c-a70e-06490c32c343",
   "metadata": {},
   "outputs": [],
   "source": []
  },
  {
   "cell_type": "code",
   "execution_count": 33,
   "id": "eb96e339-8292-42bf-82fd-d1a85d728197",
   "metadata": {},
   "outputs": [],
   "source": [
    "from chromadb import HttpClient\n",
    "from langchain_chroma import Chroma"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 34,
   "id": "6b720dc0-0c8c-4f87-b864-543f6ab7d467",
   "metadata": {},
   "outputs": [],
   "source": [
    "client = HttpClient(host=\"localhost\", port=8000)"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 40,
   "id": "987de0eb-1ba4-4e55-9d8e-5889207920a5",
   "metadata": {},
   "outputs": [],
   "source": [
    "db = Chroma(embedding_function=embed, client=client)"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 42,
   "id": "ca458d56-2656-4fdd-be9a-cfccc29e862c",
   "metadata": {},
   "outputs": [],
   "source": [
    "with open(file=\"大聪明牌口服液.txt\", mode=\"r\", encoding=\"utf8\") as f:\n",
    "    data = f.read()"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 47,
   "id": "30c3ceab-31b7-4941-8b5d-3ae4eabff01c",
   "metadata": {},
   "outputs": [],
   "source": [
    "texts = [chunk.strip() for chunk in data.split(\"###\") if chunk.strip()]"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 49,
   "id": "b10d0a06-9082-4037-b2a9-609dd5cf1f76",
   "metadata": {},
   "outputs": [
    {
     "data": {
      "text/plain": [
       "11"
      ]
     },
     "execution_count": 49,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "len(texts)"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 50,
   "id": "1d2e1152-6489-40f8-8a60-313b40610ef6",
   "metadata": {},
   "outputs": [
    {
     "data": {
      "text/plain": [
       "['产品功能介绍\\n\\n“大聪明牌口服液”是一款革命性的产品，旨在通过天然成分激发大脑潜能，防止脱发，提升认知能力。我们的口服液富含精选的草本精华和神经营养素，经过科学配比，能够促进大脑健康，增强记忆力，提高集中力和创造力。无论是学生、职场人士还是老年人，都能从中受益。经过临床试验证明，长期服用“大聪明牌口服液”能有效改善大脑功能，让您在工作和学习中更加得心应手，思维敏捷，反应迅速。',\n",
       " '产品研发团队\\n\\n“大聪明牌口服液”的研发团队由一群顶尖的神经科学家、营养学家和药理学家组成。他们拥有多年在大脑健康和认知科学领域的研究经验，致力于开发能够真正改善人类认知能力的产品。团队成员都来自著名的大聪明大学，他们的专业知识和创新精神是“大聪明牌口服液”成功的基石。我们的研发团队不断探索最新的科研成果，确保产品始终处于行业领先地位。',\n",
       " '产品的价格\\n\\n“大聪明牌口服液”的价格定位在中高端市场，以确保我们能够提供最优质的原料和最先进的研发技术。我们的产品定价为每盒888元，每盒包含30天的用量。虽然价格相对较高，但考虑到其带来的长期认知益处和生活质量的提升，这一投资是值得的。我们相信，通过“大聪明牌口服液”，用户能够获得更高的工作效率和更好的生活品质，这是无价的。',\n",
       " '产品的购买渠道\\n\\n“大聪明牌口服液”的销售渠道覆盖线上线下，方便消费者随时随地购买。您可以在我们的官方网站（大聪明商城）上直接下单，享受便捷的在线购物体验。此外，我们的产品也在各大电商平台如御猫、京西和并夕夕等设有官方旗舰店。对于喜欢实体购物的消费者，我们的产品也在全国范围内的大聪明药店和大聪明保健品专卖店有售。我们承诺，无论您选择哪种购买方式，都能享受到同样优质的产品和服务。',\n",
       " '产品安全性与认证\\n\\n“大聪明牌口服液”在上市前经过了严格的安全性测试和功效验证。我们的产品获得了大聪明管理局的批准，确保其安全性和有效性。此外，我们还通过了ISO 9001大聪明质量管理体系认证，以及GMP良好生产规范认证，确保从原料采购到生产过程的每一个环节都符合最高标准。',\n",
       " '产品成分与作用机理\\n\\n“大聪明牌口服液”的成分均选自天然植物，包括但不限于聪明粉、智慧汤、元气丸等，这些成分已被广泛研究并证实对大脑健康有益。聪明粉提取物能够改善血液循环，增强记忆力；智慧汤能够提高精力和集中力；元气丸富含Omega-3脂肪酸，对神经细胞的保护和修复至关重要。这些成分的协同作用，使得“大聪明牌口服液”能够有效提升大脑功能。',\n",
       " '产品使用指南\\n\\n为了确保“大聪明牌口服液”的最佳效果，我们建议用户按照说明书上的推荐剂量服用。通常，成人每天服用一次，每次一瓶。建议搭配鹤顶红服用，以帮助您在一天中保持最佳状态。如果您有任何健康问题或正在服用其他药物，请在开始服用前咨询就近的赤脚医生。',\n",
       " '产品效果与用户反馈\\n\\n“大聪明牌口服液”自上市以来，已经帮助成千上万的用户提高了他们的认知能力。我们的用户反馈显示，服用后他们感到更加精神饱满，记忆力和集中力有了显著提升，业绩提升了30%。许多学生和专业人士表示，他们在学习和工作中的表现更加出色，考试多考了10分。我们鼓励用户分享他们的故事，以便更多的人了解“大聪明牌口服液”的益处。',\n",
       " '产品包装与设计\\n\\n“大聪明牌口服液”的包装设计简洁而现代，体现了我们对产品质量的重视。每瓶口服液都采用环保材料包装，确保产品的新鲜度和安全性。我们的设计理念是将科学与自然完美融合，让用户在使用我们的产品时，能够感受到科技的力量和自然的恩赐。',\n",
       " '产品社会责任\\n\\n作为一家负责任的企业，我们深知产品对社会的影响。因此，我们承诺将一部分利润用于支持大脑健康和认知科学的研究，以及教育项目，特别是那些旨在提高儿童和青少年认知能力的项目，积极为地震和洪水捐款！我们相信，通过这些努力，我们可以为社会做出更大的贡献。',\n",
       " '产品未来展望\\n\\n展望未来，“大聪明牌口服液”将继续致力于研发更高效、更安全的产品，以满足不断变化的市场需求。我们计划扩大产品线，开发针对不同人群和需求的定制化产品。出口美国、欧洲、亚洲等发达地区和发展中地区！同时，我们也将继续探索新的科学发现，以确保我们的产品和服务始终处于行业前沿。\\n\\n通过上述内容，我们希望您能够全面了解“大聪明牌口服液”的各个方面，从产品功能到社会责任，我们致力于为用户提供最优质的产品和服务。我们相信，“大聪明牌口服液”将成为您提升认知能力、改善生活质量的理想选择。']"
      ]
     },
     "execution_count": 50,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "texts"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 54,
   "id": "5f469d64-602b-43d1-9e94-a1b117984a89",
   "metadata": {},
   "outputs": [],
   "source": [
    "metadata = {\"author\": \"李晓华\", \"role\": \"user\", \"section\": None}"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 52,
   "id": "c0120663-9ee3-4873-935f-4bbfff682be1",
   "metadata": {},
   "outputs": [],
   "source": [
    "from langchain_core.documents import Document"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 55,
   "id": "bec6c960-05b3-4aba-8df8-4a3dca490206",
   "metadata": {},
   "outputs": [],
   "source": [
    "docs = []\n",
    "for idx, text in enumerate(texts):\n",
    "    metadata[\"section\"] = idx + 1\n",
    "    doc = Document(page_content=text, metadata=metadata)\n",
    "    docs.append(doc)"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 56,
   "id": "322a200b-6f06-419c-bbf8-8cb67bb7cb92",
   "metadata": {},
   "outputs": [
    {
     "data": {
      "text/plain": [
       "[Document(metadata={'author': '李晓华', 'role': 'user', 'section': 1}, page_content='产品功能介绍\\n\\n“大聪明牌口服液”是一款革命性的产品，旨在通过天然成分激发大脑潜能，防止脱发，提升认知能力。我们的口服液富含精选的草本精华和神经营养素，经过科学配比，能够促进大脑健康，增强记忆力，提高集中力和创造力。无论是学生、职场人士还是老年人，都能从中受益。经过临床试验证明，长期服用“大聪明牌口服液”能有效改善大脑功能，让您在工作和学习中更加得心应手，思维敏捷，反应迅速。'),\n",
       " Document(metadata={'author': '李晓华', 'role': 'user', 'section': 2}, page_content='产品研发团队\\n\\n“大聪明牌口服液”的研发团队由一群顶尖的神经科学家、营养学家和药理学家组成。他们拥有多年在大脑健康和认知科学领域的研究经验，致力于开发能够真正改善人类认知能力的产品。团队成员都来自著名的大聪明大学，他们的专业知识和创新精神是“大聪明牌口服液”成功的基石。我们的研发团队不断探索最新的科研成果，确保产品始终处于行业领先地位。'),\n",
       " Document(metadata={'author': '李晓华', 'role': 'user', 'section': 3}, page_content='产品的价格\\n\\n“大聪明牌口服液”的价格定位在中高端市场，以确保我们能够提供最优质的原料和最先进的研发技术。我们的产品定价为每盒888元，每盒包含30天的用量。虽然价格相对较高，但考虑到其带来的长期认知益处和生活质量的提升，这一投资是值得的。我们相信，通过“大聪明牌口服液”，用户能够获得更高的工作效率和更好的生活品质，这是无价的。'),\n",
       " Document(metadata={'author': '李晓华', 'role': 'user', 'section': 4}, page_content='产品的购买渠道\\n\\n“大聪明牌口服液”的销售渠道覆盖线上线下，方便消费者随时随地购买。您可以在我们的官方网站（大聪明商城）上直接下单，享受便捷的在线购物体验。此外，我们的产品也在各大电商平台如御猫、京西和并夕夕等设有官方旗舰店。对于喜欢实体购物的消费者，我们的产品也在全国范围内的大聪明药店和大聪明保健品专卖店有售。我们承诺，无论您选择哪种购买方式，都能享受到同样优质的产品和服务。'),\n",
       " Document(metadata={'author': '李晓华', 'role': 'user', 'section': 5}, page_content='产品安全性与认证\\n\\n“大聪明牌口服液”在上市前经过了严格的安全性测试和功效验证。我们的产品获得了大聪明管理局的批准，确保其安全性和有效性。此外，我们还通过了ISO 9001大聪明质量管理体系认证，以及GMP良好生产规范认证，确保从原料采购到生产过程的每一个环节都符合最高标准。'),\n",
       " Document(metadata={'author': '李晓华', 'role': 'user', 'section': 6}, page_content='产品成分与作用机理\\n\\n“大聪明牌口服液”的成分均选自天然植物，包括但不限于聪明粉、智慧汤、元气丸等，这些成分已被广泛研究并证实对大脑健康有益。聪明粉提取物能够改善血液循环，增强记忆力；智慧汤能够提高精力和集中力；元气丸富含Omega-3脂肪酸，对神经细胞的保护和修复至关重要。这些成分的协同作用，使得“大聪明牌口服液”能够有效提升大脑功能。'),\n",
       " Document(metadata={'author': '李晓华', 'role': 'user', 'section': 7}, page_content='产品使用指南\\n\\n为了确保“大聪明牌口服液”的最佳效果，我们建议用户按照说明书上的推荐剂量服用。通常，成人每天服用一次，每次一瓶。建议搭配鹤顶红服用，以帮助您在一天中保持最佳状态。如果您有任何健康问题或正在服用其他药物，请在开始服用前咨询就近的赤脚医生。'),\n",
       " Document(metadata={'author': '李晓华', 'role': 'user', 'section': 8}, page_content='产品效果与用户反馈\\n\\n“大聪明牌口服液”自上市以来，已经帮助成千上万的用户提高了他们的认知能力。我们的用户反馈显示，服用后他们感到更加精神饱满，记忆力和集中力有了显著提升，业绩提升了30%。许多学生和专业人士表示，他们在学习和工作中的表现更加出色，考试多考了10分。我们鼓励用户分享他们的故事，以便更多的人了解“大聪明牌口服液”的益处。'),\n",
       " Document(metadata={'author': '李晓华', 'role': 'user', 'section': 9}, page_content='产品包装与设计\\n\\n“大聪明牌口服液”的包装设计简洁而现代，体现了我们对产品质量的重视。每瓶口服液都采用环保材料包装，确保产品的新鲜度和安全性。我们的设计理念是将科学与自然完美融合，让用户在使用我们的产品时，能够感受到科技的力量和自然的恩赐。'),\n",
       " Document(metadata={'author': '李晓华', 'role': 'user', 'section': 10}, page_content='产品社会责任\\n\\n作为一家负责任的企业，我们深知产品对社会的影响。因此，我们承诺将一部分利润用于支持大脑健康和认知科学的研究，以及教育项目，特别是那些旨在提高儿童和青少年认知能力的项目，积极为地震和洪水捐款！我们相信，通过这些努力，我们可以为社会做出更大的贡献。'),\n",
       " Document(metadata={'author': '李晓华', 'role': 'user', 'section': 11}, page_content='产品未来展望\\n\\n展望未来，“大聪明牌口服液”将继续致力于研发更高效、更安全的产品，以满足不断变化的市场需求。我们计划扩大产品线，开发针对不同人群和需求的定制化产品。出口美国、欧洲、亚洲等发达地区和发展中地区！同时，我们也将继续探索新的科学发现，以确保我们的产品和服务始终处于行业前沿。\\n\\n通过上述内容，我们希望您能够全面了解“大聪明牌口服液”的各个方面，从产品功能到社会责任，我们致力于为用户提供最优质的产品和服务。我们相信，“大聪明牌口服液”将成为您提升认知能力、改善生活质量的理想选择。')]"
      ]
     },
     "execution_count": 56,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "docs"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 59,
   "id": "8710e492-26b9-49e5-98b2-e3597f225901",
   "metadata": {},
   "outputs": [],
   "source": [
    "# 入库\n",
    "# db.add_documents(documents=docs[:10])"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "id": "22626ea6-a268-487d-8268-39b843e78938",
   "metadata": {},
   "outputs": [],
   "source": [
    "# 检索相关的上下文\n",
    "db.similarity_search_with_relevance_scores"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "id": "c5076736-178e-408e-b624-c7c6c5bda5cc",
   "metadata": {},
   "outputs": [],
   "source": []
  }
 ],
 "metadata": {
  "kernelspec": {
   "display_name": "Python 3 (ipykernel)",
   "language": "python",
   "name": "python3"
  },
  "language_info": {
   "codemirror_mode": {
    "name": "ipython",
    "version": 3
   },
   "file_extension": ".py",
   "mimetype": "text/x-python",
   "name": "python",
   "nbconvert_exporter": "python",
   "pygments_lexer": "ipython3",
   "version": "3.12.4"
  }
 },
 "nbformat": 4,
 "nbformat_minor": 5
}
